<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file cashs.php */
/* Location: ./cashflow/models/cashs.php */
class Cashs extends CI_Model {
    
	function __construct(){
        parent::__construct(); /** Call the Model constructor */
    }
    
    function getCashData(){
		$Q=$this->db->get('kas');
		if ($Q->num_rows() > 0):
			foreach ($Q->result_array() as $row):
				$data[$row['MataAnggaran']] = $row['MataAnggaran'] .'-'. $row['Bank'];
			endforeach;
		endif;
        $Q->free_result();
		return $data;   
	}
    
    function getCashSaldo($coa){   
        $this->db->select('Saldo');
        $this->db->where('MataAnggaran',$coa);
        $Q=$this->db->get('kas',1);
        return $Q->row_array();
    }
    
    function getCashSaldoYesterday($coa,$date_start){
        $this->db->select('Saldo');
        $this->db->where('MataAnggaran',$coa);
        $t = strtotime($date_start);
        $minus = $t - (1 * 24 * 60 * 60);
        $yest  = date('Y-m-d', $minus); 
        $this->db->where('Tanggal <=',$yest);
        $this->db->order_by('Tanggal','DESC');
        $Q=$this->db->get('kas_saldo',1);
        $value = $Q->row_array();
        if($value)
            return $value['Saldo'];
    }
    
    function getPettyCash($nmr,$coa){
        $this->db->join('petty_cash b','a.pdo_id=b.pdo_plan_id');
        $this->db->join('dt_pdo_budget c ','b.pdo_id=c.petty_cash_id ');
        $this->db->where('a.pdo_id',$nmr);
        $this->db->where('a.Bank',$coa);
        $this->db->order_by('b.NomorPO','ASC');
        $Q=$this->db->get('rekap_petty_cash a');
        return $Q->result_array();
    }
    
    function getRekapPettyCash($nmr,$coa){
        $this->db->select('Tanggal');
        $this->db->where('pdo_id',$nmr);
        $this->db->where('Bank',$coa);
        $Q=$this->db->get('rekap_petty_cash a');
        return $Q->row_array();
    }
    
    function getExcelPettyCash($no,$coa){
        $pettyCash  =  $this->getPettyCash($no,$coa); 
        $value      =  $this->getRekapPettyCash($no,$coa);
        $periode    =  indonesian_longDate($value['Tanggal']);
        $saldo      =  $this->getCashSaldo($coa);
        $saldo      =  $saldo['Saldo'];  
        
        $objPHPExcel = new PHPExcel(); /** create a new object excel **/
        /** excel properties */
        $objPHPExcel->getProperties()->setTitle("PettyCash")
					->setDescription("PettyCash");
					 $objPHPExcel->setActiveSheetIndex(0);
                     $objPHPExcel->getActiveSheet()->setTitle('PettyCash');
        /** excel Page Setup */
        $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(Worksheet_PageSetup::PAPERSIZE_A4);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.70);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.25);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.24);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.70);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setScale(60);    
        
        /** create a border **/
        $border = array('borders' => array( 'allborders' => array('style'=>Style_Border::BORDER_THIN )));
        /** create a fill coloumn **/
        $fill        = array('type'       => Style_Fill::FILL_SOLID,'rotation'=>0,'startcolor'=>array('rgb'=>'CCCCCC'),'endcolor'=>array('argb' => 'CCCCCC'));
        /** first row title page **/
        $row = 1;
        $col = 0;
        /** Daftar Bukti  **/	
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'IKHTISAR PENGELUARAN KAS KECIL');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        /** merge cell from col 0 to col 5 **/
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col,$row,$col+5,$row);
        
        /** counter row next title page **/
        $row = $row + 1;
        $col = 0;
        /** Company Name  **/	
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'PT. Bayu Buana Gemilang');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        /** merge cell from col 0 to col 5 **/
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col,$row,$col+5,$row);
        
        /** counter row next title page **/
        $row = $row + 1;
        $col = 0;
        /** Periode  **/	
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Periode '.$periode);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        /** merge cell from col 0 to col 15 **/
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col,$row,$col+5,$row);
                 
    }
    
    function getPdfPettyCash($no,$coa){
        $pettyCash  =  $this->getPettyCash($no,$coa); 
        $value      =  $this->getRekapPettyCash($no,$coa);
        $periode    =  indonesian_longDate($value['Tanggal']);
        $saldo      =  $this->getCashSaldo($coa);
        $saldo      =  $saldo['Saldo'];  
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage();
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial; 
        
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3); 
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        $pdf->SetFont('helvetica', '', 16);
        
        $pdf->SetY($y_axis0); $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial);
        $pdf->Cell(128, 8, 'IKHTISAR PENGELUARAN KAS KECIL', 0, 0, 'L', 1); 
        
        $pdf->SetFont('helvetica', '', 8);
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+136);
        $pdf->Cell(21, 4, 'Nomor ', 1, 0, 'R', 1); 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+157);
        $pdf->Cell(39, 4, $no, 1, 0, 'L', 1); 
        
        $y_axis=$y_axis+4; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+136);
        $pdf->Cell(21, 4, 'Periode ', 1, 0, 'R', 1); 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+157);
        $pdf->Cell(39, 4, $periode, 1, 0, 'L', 1); 
        
        $y_axis=$y_axis+3;
        $pdf->SetFillColor(205, 201, 201);
        $pdf->SetFont('helvetica', 'B', 7);
        
        $y_axis=$y_axis+3;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(17, 6, 'No. BPK', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+17;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(30, 6, 'Nama', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+30;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(20, 6, 'Department', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+20;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(90, 6, 'Keterangan', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+90;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(16, 6, 'No. Perk', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+16;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(23, 6, 'Jumlah', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+6;	 
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetFont('helvetica', '', 6);
        
        $i=1;
        $total = 0;
        foreach($pettyCash as $row):
            if(strlen($row['Keterangan'])>95)
                $row_height =  4 * 2;
            else
                $row_height =  4;
            $pdf->SetY($y_axis);
            $pdf->SetX($x_axis_initial); 	
			$pdf->MultiCell(17, $row_height, $row['NomorPO'], 1, 'L', 0, 0, '', '', true);
			$pdf->MultiCell(30, $row_height, $row['PIC'], 1, 'C', 0, 0, '', '', true); 
			$pdf->MultiCell(20, $row_height, $row['DeptID'], 1, 'C', 0, 0, '', '', true); 
 			$pdf->MultiCell(90, $row_height, $row['Keterangan'], 1, 'L', 0, 0, '', '', true); 
			$pdf->MultiCell(16, $row_height, $row['MataAnggaran'], 1, 'C', 0, 0, '', '', true); 
			$pdf->MultiCell(23, $row_height, number_format($row['Credit'],2,".",","), 1, 'R', 0, 0, '', '', true); 
			$y_axis=$y_axis+$row_height;
		
            $this_y=$pdf->getY();
			if($this_y >= 265):
				$pdf->AddPage();
				$x_axis_initial = 7;
				$y_axis_initial = 7;
				$x_axis = $x_axis_initial;
				$y_axis = $y_axis_initial; 

				$pdf->SetFillColor(205, 201, 201);
				$pdf->SetFont('helvetica', 'B', 7); 
				
                $y_axis=$y_axis+3;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial); 	
				$pdf->Cell(17, 6, 'No. BPK', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+17;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(30, 6, 'Nama', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+30;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(20, 6, 'Department', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+20;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(90, 6, 'Keterangan', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+90;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(16, 6, 'No. Perk', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+16;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(23, 6, 'Jumlah', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
				
				$y_axis=$y_axis+6;	 
				
				$pdf->SetFillColor(255, 255, 255);
				$pdf->SetFont('helvetica', '', 6);
			endif;
            $i++;
            $total = $total + $row['Credit'];
            $ca    = $row['Total_CA'];
        endforeach;
        
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial); 	
    	$pdf->MultiCell(33, 4, 'Dibuat', 1, 'C', 0, 0, '', '', true);
    	$pdf->MultiCell(34, 4, 'Diperiksa', 1, 'C', 0, 0, '', '', true); 
    	$pdf->MultiCell(33, 4, 'Dibukukan', 1, 'C', 0, 0, '', '', true); 
    	$pdf->MultiCell(38, 16, '', 1, 'L', 0, 0, '', '', true); 
    	$pdf->MultiCell(35, 4, 'Jumlah BPK', 1, 'L', 0, 0, '', '', true); 
    	$pdf->MultiCell(23, 4, number_format($total,2,".",","), 1, 'R', 0, 0, '', '', true); 
    	$y_axis=$y_axis+4;
  	
    	$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial); 	
    	$pdf->MultiCell(33, 12, 'Kasir', 1, 'C', 0, 0, '', '', true, 0, false, true, 12, 'B');
    	$pdf->MultiCell(34, 12, 'Mgr Keuangan', 1, 'C', 0, 0, '', '', true, 0, false, true, 12, 'B'); 
    	$pdf->MultiCell(33, 12, 'Akuntansi', 1, 'C', 0, 0, '', '', true, 0, false, true, 12, 'B'); 
    	 	
    	$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+138); 	 
    	$pdf->MultiCell(35, 4, 'Jumlah Pengeluaran CA', 1, 'L', 0, 0, '', '', true); 
    	$pdf->MultiCell(23, 4, number_format($ca,2,".",","), 1, 'R', 0, 0, '', '', true); 
    	$y_axis=$y_axis+4;
    	
    	$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+138); 	 
    	$pdf->MultiCell(35, 4, 'Uang Tunai', 1, 'L', 0, 0, '', '', true); 
    	$pdf->MultiCell(23, 4, number_format($saldo-$total,2,".",","), 1, 'R', 0, 0, '', '', true); 
    	$y_axis=$y_axis+4;
    	
    	$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+138); 	 
    	$pdf->MultiCell(35, 4, 'Jumlah Dana Kas Tetap', 1, 'L', 0, 0, '', '', true); 
    	$pdf->MultiCell(23, 4, number_format($saldo,2,".",","), 1, 'R', 0, 0, '', '', true); 
    	$y_axis=$y_axis+4;    
        return $pdf->Output("PettyCash.pdf","I");
    }
    
    function getMutationCash($date_start,$date_end,$coa){
        /** select * from bukukas
            where Bank='$coa' and (Tanggal >= '$tgl_awal' and Tanggal <= '$tgl_akhir') 
            order by Tanggal, NomorPO 
        **/
        $this->db->select('*');
        $this->db->where("(Tanggal >= '".$date_start."' and Tanggal <= '".$date_end."')");
        $this->db->where('Bank',$coa);
        $Q=$this->db->get('bukukas');
        return $Q->result_array();
    }
    
    function getExcelMutationCash($date_start,$date_end,$coa){
        /** cal invocie model **/
        $mutation = $this->getMutationCash($date_start,$date_end,$coa);
        $saldo    = $this->getCashSaldoYesterday($coa,$date_start); 
        $objPHPExcel = new PHPExcel(); /** create a new object excel **/
        /** excel properties */
        $objPHPExcel->getProperties()->setTitle("Mutasi Kas")
					->setDescription("Mutasi Kas");
					 $objPHPExcel->setActiveSheetIndex(0);
                     $objPHPExcel->getActiveSheet()->setTitle('Mutasi Kas');
        
        /** excel Page Setup */
        $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(Worksheet_PageSetup::ORIENTATION_PORTRAIT);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(Worksheet_PageSetup::PAPERSIZE_A4);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.70);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.30);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.30);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.70);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setScale(70);
        
        /** create a border **/
        $border = array('borders' => array( 'allborders' => array('style'=>Style_Border::BORDER_THIN )));
        /** create a fill coloumn **/
        $fill        = array('type'       => Style_Fill::FILL_SOLID,'rotation'=>0,'startcolor'=>array('rgb'=>'CCCCCC'),'endcolor'=>array('argb' => 'CCCCCC'));
        
        /** first row title page **/
        $row = 1;
        $col = 0;
        /** Daftar Bukti  **/	
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Mutasi Kas '.$coa);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        /** merge cell from col 0 to col 9 **/
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col,$row,$col+8,$row);
        
        /** counter row next title page **/
        $row = $row + 1;
        $col = 0;
        /** Company Name  **/	
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'PT. Bayu Buana Gemilang');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        /** merge cell from col 0 to col 7 **/
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col,$row,$col+8,$row);
        
        /** counter row next title page **/
        $row = $row + 1;
        $col = 0;
        /** Periode  **/	
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Periode '.indonesian_longDate($date_start).' s/d '.indonesian_longDate($date_end));
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        /** merge cell from col 0 to col 15 **/
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col,$row,$col+8,$row);
        
         /** row & col Column Page Title */ 
        $row = $row + 2; /** row +1*/
        $col = 0; /** coloumn 1*/ 
        
        /** coloumn Date 00*/
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,lang('date')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        
        /** coloumn No Desc 01 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,lang('description')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(30);
        
        /** coloumn COA 02 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,lang('coa')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(8);
        
        
        /** coloumn Pic Col 03 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,lang('pic')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(20); 
        
        /** coloumn Form No Col 04 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,lang('form_no')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(10); 
        
        /** coloumn Debet Col 05 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,lang('debet')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(15); 
        
        /** coloumn Credit Col 06 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,lang('credit')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(15); 
        
        /** coloumn Saldo Col 07 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,lang('saldo')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(15); 
        
        /** coloumn Rp Col 08 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,lang('dept')); 
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($border);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getFill()->applyFromArray($fill);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+8)->setWidth(15);
        
        /** row & col Column Content */ 
        $row = $row + 1; /** row +1*/
        $col = 0; /** coloumn 1*/ 
        $i=1;  /** no **/
        $saldo = $saldo;
        foreach($mutation as $val):
            /** coloumn Date **/ 
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,indonesian_date($val['Tanggal']));
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($border);
            
            /** coloumn Desc **/ 
            if($i==1):
                $desc = 'Saldo Awal';
                $saldo = $saldo;
            else:
                $desc =  $val['Uraian'];  
                $saldo = ($saldo + $val['Masuk'])-$val['Keluar'];
            endif;      
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$desc);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($border);
            
            /** coloumn COA  **/ 
            if($i==1)
                $co = $coa;
            else
                $co = $val['MataAnggaran']; 
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$co);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($border);
            /** coloumn PIC **/ 
            if($i==1)
                $pic = '';
            else
                $pic = $val['PIC'];  
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$pic);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($border);
            /** coloumn Form No **/
            if($i==1)
                $no = '';
            else 
                $no = $val['NomorPO'];
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$no);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($border);
            /** coloumn Debet **/ 
            if($i==1)
                $debet = '';
            else 
                $debet = $val['Masuk'];
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,decimal($debet,2));
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_RIGHT);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($border);
            /** coloumn Credit **/ 
            if($i==1)
                $credit = '';
            else 
                $credit = $val['Keluar'];
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,decimal($credit,2));
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($border);
            /** coloumn Saldo **/  
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,decimal($saldo,2));
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_RIGHT);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($border);
            /** coloumn Dept **/  
            if($i==1)
                $dept = '';
            else 
                $dept = $val['DeptID'];
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$dept);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($border);
            
            /** counter**/
            $i++;
            $row++;
        endforeach;
        /** Save it as an excel 2007 file */
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel2007");
        $file = "Invoice Payment.xls";
        $objWriter->save($file);
        return $file;
    }
    
    function getPdfMutationCash($date_start,$date_end,$coa){
        $mutation = $this->getMutationCash($date_start,$date_end,$coa);
        $saldo    = $this->getCashSaldoYesterday($coa,$date_start); 
        
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage();
        
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial;
        
        $pdf->SetFont('helvetica', '', 8);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3);
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis); 
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 4, 'Mutasi Kas '.$coa, 0, 0, 'C', 1);
        
        $y_axis=$y_axis+4; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 4, 'PT. Bayu Buana Gemilang', 0, 0, 'C', 1); 
        
        $y_axis=$y_axis+4; 
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 4, 'Periode '.indonesian_longDate($date_start).' s/d '.indonesian_longDate($date_end), 0, 0, 'C', 1); 
        
        $y_axis=$y_axis+3;
        
        $pdf->SetFillColor(205, 201, 201);
        $pdf->SetFont('helvetica', 'B', 7); 
        
       	$y_axis=$y_axis+3;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial); 	
        $pdf->Cell(13, 6, 'Tanggal', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+13;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(60, 6, 'Uraian', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+60;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(10, 6, 'COA', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $x_axis=$x_axis+10;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(29, 6, 'PIC', 1, 1, 'C', 1, '', 0, false, 'T', 'C'); 
        
        $x_axis=$x_axis+29;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(16, 6, 'NO Form', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+16;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(17, 6, 'Debet', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+17;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(17, 6, 'Kredit', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+17;
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(20, 6, 'Saldo', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
       	$x_axis=$x_axis+20; 
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis); 	
        $pdf->Cell(14, 6, 'Dept', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
        
        $y_axis=$y_axis+6;
        
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetFont('helvetica', '', 6);	
        
        $i = 1;
        foreach($mutation as $row):
            $this_y=$pdf->getY();
			if($this_y >= 265):
				$pdf->AddPage();
                
				$x_axis_initial = 7;
				$y_axis_initial = 7;
				$x_axis = $x_axis_initial;
				$y_axis = $y_axis_initial; 

				$pdf->SetFillColor(205, 201, 201);
				$pdf->SetFont('helvetica', 'B', 7); 
				
                $y_axis=$y_axis+3;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial); 	
				$pdf->Cell(13, 6, 'Tanggal', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+13;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(60, 6, 'Uraian', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+60;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(10, 6, 'COA', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+10;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(29, 6, 'PIC', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+29;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(16, 6, 'No Form', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+16;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(17, 6, 'Debet', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+17;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(17, 6, 'Kredit', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
				
                $x_axis=$x_axis+17;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(20, 6, 'Saldo', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
				$x_axis=$x_axis+20;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
				$pdf->Cell(14, 6, 'Dept', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
				$y_axis=$y_axis+6;	 
				
				$pdf->SetFillColor(255, 255, 255);
				$pdf->SetFont('helvetica', '', 6);
			endif;
            
            $data = strlen($row['Uraian']);
            if($data > 118)
				$row_height=3 * 3;
            elseif($data > 50)
                $row_height=2 * 4;    				 			
			else
				$row_height=4;				 
			
            $saldo=$saldo+$row['Masuk']-$row['Keluar'];
            
            if($i==1):
				$pdf->SetY($y_axis); $pdf->SetX($x_axis_initial); 	
				$pdf->MultiCell(13, $row_height, indonesian_date($row['Tanggal']), 1, 'C', 0, 0, '', '', true);
				$pdf->MultiCell(60, $row_height, 'Saldo Awal', 1, 'L', 0, 0, '', '', true); 
				$pdf->MultiCell(10, $row_height, $coa, 1, 'C', 0, 0, '', '', true); 
				$pdf->MultiCell(29, $row_height, '', 1, 'L', 0, 0, '', '', true); 
				$pdf->MultiCell(16, $row_height, '', 1, 'C', 0, 0, '', '', true); 
				$pdf->MultiCell(17, $row_height, '', 1, 'R', 0, 0, '', '', true); 
				$pdf->MultiCell(17, $row_height, '', 1, 'R', 0, 0, '', '', true); 
				$pdf->MultiCell(20, $row_height, number_format($saldo,2,".",","), 1, 'R', 0, 0, '', '', true); 
				$pdf->MultiCell(14, $row_height, '', 1, 'L', 0, 0, '', '', true); 
				$y_axis=$y_axis+$row_height;
			else:
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial); 	
    			$pdf->MultiCell(13, $row_height, indonesian_date($row['Tanggal']), 1, 'C', 0, 0, '', '', true);
    			$pdf->MultiCell(60, $row_height, $row['Uraian'], 1, 'L', 0, 0, '', '', true); 
    			$pdf->MultiCell(10, $row_height, $row['MataAnggaran'], 1, 'C', 0, 0, '', '', true); 
     			$pdf->MultiCell(29, $row_height, $row['PIC'], 1, 'C', 0, 0, '', '', true); 
    			$pdf->MultiCell(16, $row_height, $row['NomorPO'], 1, 'L', 0, 0, '', '', true); 
    			$pdf->MultiCell(17, $row_height, number_format($row['Masuk'],2,".",","), 1, 'R', 0, 0, '', '', true); 
    			$pdf->MultiCell(17, $row_height, number_format($row['Keluar'],2,".",","), 1, 'R', 0, 0, '', '', true); 
    			$pdf->MultiCell(20, $row_height, number_format($saldo,2,".",","), 1, 'R', 0, 0, '', '', true); 
    			$pdf->MultiCell(14, $row_height, $row['DeptID'], 1, 'C', 0, 0, '', '', true); 
    			$y_axis=$y_axis+$row_height;
            endif;
            $i++;
        endforeach;      
        
        return $pdf->Output("MutationCash.pdf","I");
    }
    
    function getCashFlow($year,$month,$account){
        /** select * from dt_cash_flow 
            where Tahun='$thn' and Bulan='$bln' 
            and MataAnggaran='$row_budget[MataAnggaran]' order by Tanggal 
        **/
        $this->db->where('Tahun',$year);
        $this->db->where('Bulan',$month);
        $this->db->where('MataAnggaran',$account);
        $this->db->order_by('Tanggal','ASC');
        $Q=$this->db->get('dt_cash_flow');
        return $Q->result_array();
    }
    
    function getPdfGeneralLedger($month,$year,$account){
        $budgets  = $this->budgets->getDataBudget('H1','H2');
        $accounts = $this->budgets->getBudgetAccount(substr($account,0,3));
        
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage(); 
        /** initialization of x & y axis **/
        $x_axis_initial = 7;
        $y_axis_initial = 7;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial;
        
        $pdf->SetFont('helvetica', '', 12);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3);
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        
        $pdf->SetY($y_axis0);
        $pdf->SetX($x_axis_initial); 	
        $pdf->SetY($y_axis);
        $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 6, 'Buku Besar', 0, 0, 'C', 1); 
        
        $y_axis=$y_axis+6; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+4);
        $pdf->Cell(190, 6, 'Periode '.month_name($month).' '.$year, 0, 0, 'C', 1); 
        $y_axis=$y_axis+7;
        
        $i=0;
        $anggaranh=0;
        $realh=0;
        $anggaranh_thn=0;
        $realh_thn=0; 
        $anggaran1=0;
        $real1=0;
        $anggaran_thn=0;
        $real_thn=0; 
        $index_h=-1;
        $index_h1=-1;
        $index_h2=-1;
        $index_h3=-1;
        $index_h4=-1;
        foreach($accounts as $row):
            $ledger = $this->cashs->getCashFlow($year,$month,$row['MataAnggaran']);
            if(COUNT($ledger)):
                $pdf->SetFont('helvetica', '', 8);
        		$y_axis=$y_axis+2;
        		$pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial+4);
        		$pdf->Cell(100, 6, 'Nama Akun : '.$row['Ikhtisar'], 0, 0, 'L', 1); 
                
        		$x_axis=$x_axis_initial+144;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis);
        		$pdf->Cell(50, 6, 'Kode : '.$row['MataAnggaran'], 0, 0, 'L', 1); 
                
                $x_axis=$x_axis_initial;  
        		$pdf->SetFillColor(205, 201, 201);
        		$pdf->SetFont('helvetica', 'B', 7); 
       			$y_axis=$y_axis+7;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis_initial); 	
        		$pdf->Cell(16, 8, 'TANGGAL', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
       			$x_axis=$x_axis+16;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(78, 8, 'KETERANGAN', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
       			$x_axis=$x_axis+78;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(14, 8, 'DEPT', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
       			$x_axis=$x_axis+14;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(21, 8, 'DEBET', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
       			$x_axis=$x_axis+21;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(21, 8, 'KREDIT', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
       			$x_axis=$x_axis+21;
                $pdf->SetY($y_axis);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(46, 4, 'SALDO', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
        		$pdf->SetY($y_axis+4);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(23, 4, 'DEBET', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                
        		$x_axis=$x_axis+23;
                $pdf->SetY($y_axis+4);
                $pdf->SetX($x_axis); 	
        		$pdf->Cell(23, 4, 'KREDIT', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
         			 	
        		$y_axis=$y_axis+8;	 
        		$pdf->SetFillColor(255, 255, 255);
                
                $saldo_credit=0;
                $saldo_debet=0;
                $credit=0;
                $debet=0;
                $i=0;
                foreach($ledger as $val):
                    /** Credit & Debet **/
                    if($val['cash_id_in']!=0 || $val['cash_id_transfer']!=0):/** masuk kredit **/
             			$credit= $val['Credit'];
             			$debet = 0;
              		elseif($val['cash_id_out']!=0 || $val['petty_cash_id']!=0): /** masuk debet **/
         			    $debet = $val['Credit'];
             			$credit= 0;
              		endif;
                                        
                    /** Saldo **/
                    if($i==0):
             			if($credit!=0)
           				     $saldo_credit= $credit;				 
             			else $saldo_debet = $debet;            			 
              		else:
             			if($credit!=0):
            				if($saldo_credit!=0):
           					    $saldo_credit=$saldo_credit+$credit;				 
            				else:
           					    $saldo_debet=$saldo_debet-$credit;				 
               					if($saldo_debet < 0):
              						$saldo_credit=abs($saldo_debet);
              						$saldo_debet=0;
               					endif;
            				endif; 
             			else:
            				if($saldo_debet!=0):
           					    $saldo_debet=$saldo_debet+$debet;
            				else:
           					    $saldo_credit=$saldo_credit-$debet;
               					if($saldo_credit < 0):
              						$saldo_debet=abs($saldo_credit);
              						$saldo_credit=0;
               					endif;
            				endif;
             			endif;               
                    endif; 
                                        
                    /** Credit & Debit **/
                    if($credit!=0):
             			$is_credit= number_format($credit,2,".",",");
             			$is_debet = "";
              		endif;
              		if($debet!=0):
             			$is_debet = number_format($debet,2,".",",");
             			$is_credit= "";
              		endif;
                                        
                    /** saldo Credit & Debit **/
                    if($saldo_credit!=0):
             			$is_saldo_credit=number_format($saldo_credit,2,".",",");
             			$is_saldo_debet="";
              		endif;
                                        
              		if($saldo_debet!=0):
             			$is_saldo_debet=number_format($saldo_debet,2,".",",");
             			$is_saldo_credit="";
              		endif;                    
                    $pdf->SetFont('helvetica','',6);
		            $data = strlen($val['Keterangan']);
		
            		if($data > 67)
            			$row_height= 3 * 3;				 			
            		else
            			$row_height= 4;				 
		
            		$pdf->SetY($y_axis);
                    $pdf->SetX($x_axis_initial); 	
            		
            		$pdf->MultiCell(10,$row_height, $month, 1, 'L', 0, 0, '', '', true);
            		$pdf->MultiCell(6,$row_height,  substr($val['Tanggal'],8,2), 1, 'C', 0, 0, '', '', true);
            		$pdf->MultiCell(78,$row_height, $val['Keterangan'].'   ', 1, 'L', 0, 0, '', '', true); 
            		$pdf->MultiCell(14,$row_height, $val['DeptId'], 1, 'C', 0, 0, '', '', true); 
            		$pdf->MultiCell(21,$row_height, $is_debet, 1, 'R', 0, 0, '', '', true); 
            		$pdf->MultiCell(21,$row_height, $is_credit, 1, 'R', 0, 0, '', '', true); 
            		$pdf->MultiCell(23,$row_height, $is_saldo_debet, 1, 'R', 0, 0, '', '', true); 
            		$pdf->MultiCell(23,$row_height, $is_saldo_credit, 1, 'R', 0, 0, '', '', true); 
            		$y_axis=$y_axis+$row_height;
                    
                    $this_y=$pdf->getY();
            		if($this_y >= 260):
            			$pdf->AddPage();
            			$x_axis_initial = 7;
            			$y_axis_initial = 7;
            			$x_axis = $x_axis_initial;
            			$y_axis = $y_axis_initial; 
            			
            			$pdf->SetFillColor(205, 201, 201);
            			$pdf->SetFont('helvetica', 'B', 8); 
                        
           				$pdf->SetY($y_axis);
                        $pdf->SetX($x_axis_initial); 	
            			$pdf->Cell(16, 8, 'TANGGAL', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
           				$x_axis=$x_axis+16;
                        $pdf->SetY($y_axis);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(78, 8, 'KETERANGAN', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
           				$x_axis=$x_axis+78;
                        $pdf->SetY($y_axis);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(14, 8, 'DEPT', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
           				$x_axis=$x_axis+14;
                        $pdf->SetY($y_axis);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(21, 8, 'DEBET', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
           				$x_axis=$x_axis+21;
                        $pdf->SetY($y_axis);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(21, 8, 'KREDIT', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
           				$x_axis=$x_axis+21;
                        $pdf->SetY($y_axis);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(46, 4, 'SALDO', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
            			$pdf->SetY($y_axis+4);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(23, 4, 'DEBET', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
                        
            			$x_axis=$x_axis+23;
                        $pdf->SetY($y_axis+4);
                        $pdf->SetX($x_axis); 	
            			$pdf->Cell(23, 4, 'KREDIT', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
            					
            			$y_axis=$y_axis+8;	 
            			$x_axis = $x_axis_initial;
           			
            			$pdf->SetFillColor(255, 255, 255);		
            		endif;
        
                    $i++;
                endforeach;
                
            endif;
        endforeach;
        
        
        return $pdf->Output("GL.pdf","I"); 
    }     
}